1. Field of the Invention
The present invention relates to a method, system, and program for generating an interface to elements in a document.
2. Description of the Related Art
The Extended Mark-up Language (XML), which is a subset of the Standard Generalized Markup Language (SGML), is designed to provide the capability to exchange structured documents over the Internet. XML files clearly mark where the start and end of each of the logical parts (called elements) of an interchanged document occur. For instance, if the XML document defines a book, the elements would include the table of contents, chapters, appendices, etc. The XML document includes a definition of each element in a formal model, known as a Document Type Definition (DTD). The DTD provides attributes for each element and indicates the relationship of the elements. Elements may be arranged in a hierarchical relationship. In such case, the DTD would define the hierarchical relationship of the elements to one another. Further details of XML are described in the publication “Extensible Markup Language (XML) 1.0, document no. REC-xml-19980210 (Copyright W3C, 1998), which publication is incorporated herein by reference in its entirety.
Users can encode and view an XML document with the Document Object Model (DOM) application program interface (API). The DOM interface is described in the publication entitled “Document Object Model (DOM) Level 1 Specification, Version 1.0,” document no. REC-DOM-Level-1-19981001 (Copyright W3C 1998), which publication is incorporated herein by reference in its entirety. The DOM interface represents the document as a hierarchical arrangement of nodes. When applied to the XML document, each node comprises one of the elements. For instance, the user may define the DTD (1) below to include elements of a book.<?xml version=“1.0”><Book title=“ The NetRexx Language><Contents>. . . <Contents><Chapter title=“Background”. . . </Chapter><Chapter title=“Overview”. . . </Chapter><Chapter title=“Definition”>. . .</Chapter><Appendix>. . . </Appendix></Book>  (1)
The DOM interface would represent the above elements in the tree illustrated in FIG. 1. To access elements in the node, the user must generate code to traverse the hierarchical nodes by specifying the node number. For instance, to access the title attribute of the “Background Chapter” element defined in the DTD (2) above, the following code (2) is needed:Element bookElement= document.getDocumentElement(); NodeList= bookElement.getChildNodes();Element chapter= (Element) list.item(1); String title= chapter.getAttribute(“title”);  (2)
The document.getDocumentElement( ) method accesses the root node of the document, the getChildNodes( ) method accesses the child nodes of the first element, which the DTD (1) defines as the table of contents (“contents”), and the list.item(1) accesses the first child or chapter node, which is the “Background Chapter.” The method chapter.getAttribute (“title”) obtains the title of the element at the first child node, which is “Background Chapter”. Thus, in order to access an element using current DOM interface techniques, the user must know beforehand the mapping between the name and position (e.g., the first node is a chapter element) of each node of the tree to reach the desired node.
There is thus a need in the art to provide an improved method, system, and program for accessing elements within a document, such as an XML document, and manipulating the elements.